#region Imported Namespaces
using System;
using System.Collections.Specialized;
using System.Data;
using System.Web.UI.WebControls;

using PHSRAG.Insight21.Context;
using BO = PHSRAG.Insight21.BusinessObjects;
using DataAccess = PHSRAG.Utility.DataAccess;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using AgreementsConstants = PHSRAG.Insight21.InsightUtilities.Constants.AgreementsConstants;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.SearchContext
{
	#region Class OverviewSearchContext
	/// <summary>
	/// The OverviewSearchContext class encapsulates the search context associated with the OverviewSearch control.
	/// </summary>
	public class OverviewSearchContext : SearchContext
	{
		#region Constants
		private static string OverviewSearchContextKey	= GenerateKey.MakeKey("OverviewSearchContext_2C25FCEC-9C5A-40E9-A827-7447155533D4",GenerateKey.Common);
		private const string GetCategoriesSPROCName		= "GetCategories";
		private const string GetAccountNumbersSPROCName	= "GetAccounts";
		private const int AccountsTableIndex			= 0;
		private const int DefaultCategoryID				= 0;
		#endregion

		#region Class Properties
		/// <summary>
		/// Get the key to be used in all caching operations for this instance of the object.
		/// </summary>
		public static string CacheKey	{ get { return OverviewSearchContextKey; } }
		#endregion

		#region Constructor
		/// <summary>
		/// Create an instance of the OverviewSearchContext class. Initialize the base class
		/// </summary>
		/// <param name="cachePolicy">The active cache policy</param>
		public OverviewSearchContext(ICachePolicy cachePolicy):base(cachePolicy)
		{
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Get/set the data table from the data container which contains data for the categories drop-down-list.
		/// </summary>
		public DataTable Categories
		{
			get 
			{
				object categoryTable = DataContainer.Tables[AgreementsConstants.DisplayCategoriesTableName];
				return (categoryTable == null)?new DataTable():(DataTable)categoryTable;
			}
			set
			{
				DataTable categoryTable = value as DataTable;
				categoryTable.TableName = AgreementsConstants.DisplayCategoriesTableName;
				if(DataContainer == null) DataContainer = new DataSet();
				if(DataContainer.Tables.Contains(AgreementsConstants.DisplayCategoriesTableName))
					DataContainer.Tables.Remove(AgreementsConstants.DisplayCategoriesTableName);
				DataContainer.Tables.Add(categoryTable);
			}
		}
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache this instance of the OverviewSearchContext object using the current cache policy.
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(CacheKey, this);
		}
		/// <summary>
		/// Load overview search data into the data container. The loading is done by invoking a stored procedure.
		/// </summary>
		/// <param name="connectionString">Connection string to the database</param>
		/// <param name="args">To load account level information the categoryID is mandatory</param>
		public override void Load(string connectionString, params object[] args)
		{
			if(DataContainer == null) DataContainer = new DataSet();
		}
		/// <summary>
		/// Remove this instance of the OverviewSearchContext object from the cache using the current cache policy.
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(CacheKey);
		}
		#endregion

		#region SearchContext Members
		/// <summary>
		/// Reset the internal search state.
		/// </summary>
		public override void Reset(string pageName)
		{
			// for now, nothing needs to be done
		}
		#endregion
	}
	#endregion
}

// --- EOF ---